
#ifndef STATISTICS_HPP
#define STATISTICS_HPP

#include <vector>
#include <cmath>

using namespace std;

template <class T> pair<T,T> MeanStdDev ( const vector<T>& p_vec, int p_len )
{
  int len = p_len;
  if ( len <= 0 )
    len = p_vec.size();

  T mean = 0, sumsq = 0;

  for ( int i = 0; i < len; ++i )
    {
      T tmp = p_vec[i];
      mean += tmp;
      sumsq += tmp*tmp;
    }
  mean /= len;
  // sample var
  T var = sumsq - len * mean * mean;
  var /= len - 1;
  pair<T,T> retval (mean,sqrt(var));
  return retval;
}

#endif
